module ai {
	/*
 	* 一个简单的开局库，用花月+浦月必胜开局
 	*/
	export class Opening extends BaseClass {
		private math: ai.ChessMath = ai.ChessMath.getInstance();
		public constructor() {
			super();
		}

		private huayue(board) {
			Log.trace('使用花月开局')
			var s = board.allSteps;
			if (this.math.pointEqual(s[1], [6, 7])) {
				if (s.length === 2) return [6, 8]
			}
			if (this.math.pointEqual(s[1], [7, 6])) {
				if (s.length === 2) return [6, 6]
			}
			if (this.math.pointEqual(s[1], [8, 7])) {
				if (s.length === 2) return [8, 6]
			}
			if (this.math.pointEqual(s[1], [7, 8])) {
				if (s.length === 2) return [8, 8]
			}
		}

		private puyue(board) {
			Log.trace('使用浦月开局')
			var s = board.allSteps;
			if (this.math.pointEqual(s[1], [6, 6])) {
				if (s.length === 2) return [6, 8]
			}
			if (this.math.pointEqual(s[1], [8, 6])) {
				if (s.length === 2) return [6, 6]
			}
			if (this.math.pointEqual(s[1], [8, 8])) {
				if (s.length === 2) return [8, 6]
			}
			if (this.math.pointEqual(s[1], [6, 8])) {
				if (s.length === 2) return [8, 8]
			}
		}
		public match(board) {
			var s = board.allSteps;
			if (board.board[s[0][0]][s[0][1]] !== 1) return false
			if (s.length > 2) return false
			if (this.math.containPoint([[6, 7], [7, 6], [8, 7], [7, 8]], s[1])) return this.huayue(board);
			else if (this.math.containPoint([[6, 6], [8, 8], [8, 6], [6, 8]], s[1])) return this.puyue(board);
			return false
		}
	}
}